Modul:FacebookCite
-- This module implements Template:FacebookCite. local p = {} local lang = mw.language.getContentLanguage() local currentTitle = mw.title.getCurrentTitle() local function makeCategoryLink(cat) -- "Category" is split out here so that the module isn't put into the -- category "%s" when the page is saved. return string.format('%s:%s', 'Category', cat) end local function makeWikitextError(msg) local ret = '' ret = ret .. string.format( 'Template:FacebookCite error: %s.', msg ) if currentTitle.namespace 0 then ret = ret .. makeCategoryLink('Pages with template parameter errors') end return ret end local function formatDate(format, date) local success, date = pcall(lang.formatDate, lang, format, date) if success then return date end end local function makeLinkedDate(date) return formatDate('F j, Y', date) end local function formatDateAndTime(date, time) date = makeLinkedDate(date) if not date then return nil end if time then time = formatDate('g:i a', time) if not time then return nil end end if time then time = string.format(', %s', time) else time = '' end return date .. time end local function makeArchiveLink(archive, description) if archive:find('^http') then return string.format('%s', archive, description) else return string.format('%s', archive, description) end end function p._main(args) -- Validate parameters that are always needed if not args.description then return makeWikitextError( "the 'description' parameter must be specified" ) end local ret = {} -- Shortcut function for adding new strings local function add(val) ret+ 1 = val end -- Facebook icon add(' ') -- Start citation details. If a userpage was specified, we ignore the other -- citation details. if args.userpage then add(string.format( '%s on Facebook', args.userpage, args.description )) else -- Validate parameters that are only required if args.userpage is not -- set. if not args.author or not args.dateposted then return makeWikitextError( "if the 'userpage' parameter is not set, parameters " .. "'author' and 'dateposted' must be specified" ) elseif not args.link and not args.archive then return makeWikitextError( "if the 'userpage' parameter is not set, either 'link' or " .. "'archive' must be specified" ) end -- Link or archive link if args.link then add(string.format( '%s.', args.link, args.description )) elseif args.archive then add(makeArchiveLink(args.archive, args.description) .. '.') end -- Author add(' ') add(args.author) -- Date and time posted do local date = formatDateAndTime(args.dateposted, args.timeposted) if date then add(string.format(' (%s).', date)) elseif not args.timeposted then return makeWikitextError( "tanggal tidak valid dalam parameter 'dateposted'" ) else return makeWikitextError( "tanggal tidak valid dalam parameter 'dateposted' atau 'timeposted'" ) end end -- Date and time accessed if args.dateaccessed then local date = formatDateAndTime(args.dateaccessed, args.timeaccessed) if date then add(string.format(' Retrieved on %s.', date)) elseif not args.timeaccessed then return makeWikitextError( "tanggal tidak valid dalam parameter 'dateaccessed'" ) else return makeWikitextError( "tanggal tidak valid dalam parameter 'dateaccessed' or 'timeaccessed'" ) end end -- Quote if args.quote then add(string.format(' "%s"', args.quote)) end -- Archive if args.link and args.archive then local archive = makeArchiveLink(args.archive, 'salinan archive') if args.archivedate then local date = makeLinkedDate(args.archivedate) if not date then return makeWikitextError( "tanggal tidak valid dalam parameter 'archivedate'" ) end archive = archive .. ' dibuat dalam ' .. date end add(string.format(' (%s)', archive)) elseif args.archivedate and not args.link then local date = makeLinkedDate(args.archivedate) if not date then return makeWikitextError( "tanggal tidak valid dalam parameter 'archivedate'" ) end add(string.format( ' salinan arsip dibuat pada %s)', date )) end end -- Image if args.image then add(string.format(' (cuplikan)', args.image)) end if args.noimage then add(string.format(' (Konten tidak tersedia lagi)')) end -- Screenshot tracking category if not args.userpage and not args.archive and not args.image and not args.noimage and currentTitle.namespace 0 then add('Category:Kutipan media sosial tanpa cuplikan') end return table.concat(ret) end function p.main(frame) local args = {} for k, v in pairs(frame:getParent().args) do v = v:match('^%s*(.-)%s*$') -- trim whitespace if v ~= '' then argsk = v end end return p._main(args) end return p --